|
|
|
|
|
|
|
Now in the Form_Load() event for this form, you can use the mlngEmpTypeID variable to change the RecordSource property of a data control: |
|
|
|
 |
|
|
|
|
Private Sub Form_Load()
Dim strSQL As String
If mlngEmpTypeID <> -1 Then strSQL = "SELECT * FROM tblEmployees "
strSQL = strSQL & " WHERE lEmpType_id = " & _
mlngEmpTypeID
adatEmployees.RecordSource = strSQL
adatEmployees.Refresh
End If
End Sub |
|
|
|
|
|
|
|
|
In this code, you check mlngEmpTypeID to see whether its equal to 1. If it isnt, you know that the property has been set from another form. The reason you know this is because in the Form_Initialize() event, you set the mlngEmpTypeID to 1: |
|
|
|
 |
|
|
|
|
Private Sub Form_Initialize()
mlngEmpTypeID = -1
End Sub |
|
|
|
|
|
|
|
|
Because the Form_Initialize() event happens before any property is set, the value will always be initialized to 1. Then, if you call the Property Let procedure, you override the value with the employee type ID you pass in. |
|
|
|
|
|
|
|
|
Lets now build a class that helps you read and write information in an ASCII text file. This class will encapsulate some of the low-level file I/O statements of Visual Basic so they can have a more object-oriented flavor. It can be a real pain dealing with all the file handles and different methods of opening files, as well as just reading from and writing to ASCII files. To eliminate some of the drudgery, this file I/O class handles the details for you, so all you need to do is set some properties and invoke some methods. This class module has already been built and is available in the sample project for this chapter. |
|
|
|
|
|